#include "sExp.h"

sExp::sExp()
{
	union64 = 0;
}


bool sExp::add(int v_, bool onlyCheck /* = false */)
{
	if (v_ >= 0)
	{
		if (!onlyCheck)
		{
			w = w + v_ / 10000;
			v = v + v_ % 10000;
			if (v > 10000)
			{
				v = v - 10000;
				w = w + 1;
			}
		}
		return true;
	}
	v_ = -v_;
	if (*this < v_)
	{
		return false;
	}
	if (!onlyCheck)
	{
		w = w - v_ / 10000;
		if (v > v_ % 10000)
		{
			v = v - v_ % 10000;
		}
		else
		{
			w = w - 1;
			v = v + (10000 - (v_ % 10000));
		}
	}
	return true;
}

int sExp::getExp(int lv, bool pet)
{
	if (pet)
	{
		if (lv == 0)
		{
			return 10;
		}
		if (lv == ccp::lv180 + 1)
		{
			return 800000000;
		}
		int exp = lv * 10000;
		exp = exp * lv / ccp::lv180;
		return exp;
	}
	static std::vector<int> s_expTable =
	{
		10, 40, 110, 237, 450, 779, 1252, 1898, 2745, 3822, 5159, 6784,
		8726, 11013, 13674, 16739, 20236, 24149, 28641, 33606, 39119, 45208,
		51902, 59229, 67218, 75899, 85300, 95450, 106377, 118110, 130679, 144112,
		158438, 173685, 189882, 207059, 225244, 244466, 264753, 286134, 308639, 332296,
		357134, 383181, 410466, 439019, 468868, 500042, 532569, 566478, 601799, 638560,
		676690, 716517, 757770, 800579, 844972, 890978, 938625, 987942, 1038959, 1091704,
		1146206, 1202493, 1260594, 1320593, 1382356, 1446074, 151172, 1579326, 1648919, 1720528,
		1794182, 1869909, 1947738, 2027699, 2109820, 2194130, 2280657, 2369431, 2460479, 2553832,
		2649518, 2747565, 2848003, 2950859, 3056164, 3163946, 3274233, 3387055, 3502439, 3620416,
		3741014, 3864261, 3990187, 4118819, 4250188, 4384322, 4521249, 4660999, 4803599, 4998571,
		5199419, 5406260, 5609213, 5838379, 6063933, 6295941, 6534544, 6779867, 7032035, 7291172,
		7557407, 7830869, 8111686, 8399990, 8695912, 8999586, 9311145, 9630726, 9958463, 10294496,
		10638964, 10992005, 11353761, 11724374, 12103988, 12492748, 12890799, 13298287, 13715362, 14142172,
		14578867, 15025600, 15482522, 15949788, 16427552, 16915970, 17415202, 17925402, 18446732, 18979354,
		19523428, 20079116, 20646584, 21225998, 43635044, 44842648, 46075148, 47332886, 48616200, 74888150,
		76891401, 78934581, 81018219, 83142834, 85308968, 87517159, 89767944, 92061872, 94399488, 129041783,
		132277315, 135573313, 138930533, 142349724, 218747456, 224065576, 229840080, 234992173, 240602904, 533679362,
		819407100, 1118169974, 1430306664, 1756161225, 2000000000, 2000000000, 2000000000, 2000000000
	};
	return s_expTable[lv];
}